package nju.mscs.data.object;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;

public class Bill implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -89118933487655843L;
	private VipConsumer vip;
	private User cashier;
	private ArrayList<SaleGoods> goodsList = new ArrayList<SaleGoods>();
	private ArrayList<Gift> giftsList = new ArrayList<Gift>();
	private ArrayList<Promotion> promoyionList = new ArrayList<Promotion>();
	private String id;
	private Calendar time;//改成Ca
	private ArrayList<ReturnBill> rb=new ArrayList<ReturnBill>();
	
	protected Bill(String id,VipConsumer vip,User cashier){
		setVip(vip);
		this.id = id;
		this.cashier = cashier;
		time=Calendar.getInstance();
	}
	public VipConsumer getVip() {
		return vip;
	}

	public void setVip(VipConsumer vip) {
		this.vip = vip;
	}
	
	public void addGoods(Goods goods,int sum,double discount){
		this.goodsList.add(new SaleGoods(goods, sum, discount));
	}
	public void addGift(Gift gift){
		giftsList.add(gift);
	}
	
	public void addPromotion(Promotion promotion){
		this.promoyionList.add(promotion);
	}
	public String print(){
		String text = "********************\n";
				if(this.vip==null){
					text+="";
				}
				else{
					text+=("vip:"+this.vip.getName()+'\n')+"cachier:"+this.cashier.getName();
				}
		for(SaleGoods sg:goodsList)
			text+=sg.toString()+'\n';
		return text;
	}
	public User getCashier() {
		return cashier;
	}
	public ArrayList<SaleGoods> getGoodsList() {
		return goodsList;
	}
	public ArrayList<Gift> getGiftsList() {
		return giftsList;
	}
	public ArrayList<Promotion> getPromoyionList() {
		return promoyionList;
	}
	public String getId() {
		return id;
	}
	public Calendar getTime() {
		return time;
	}
	public ReturnBill creatReturnBill(User ca,ArrayList<Goods> rg,double mo){
		ReturnBill r=new ReturnBill(ca,vip,rg,mo);
		rb.add(r);
		return r; 
	}
	public ArrayList<ReturnBill> getRb() {
		return rb;
	}
	public SaleGoods searchGoods(String id){
		SaleGoods result=null;
		for(SaleGoods sg:goodsList){
			if(sg.getGoods().getId().equals(id))
				result=sg;
		}
		return result;
	}	
}
